/*
*
* */
$(document).ready(function () {
    $('#newAdd').on('click', function () {
        console.log("你好")
        $.ajax({
            url: 'user/form',
            type: "get",
            success: function (htmlData) {
                layer.open({
                    type: 1,
                    title: "用户新增表单",
                    area: ['500px', '300px'],
                    content: htmlData,
                    success: function (layer, index) {
                        buildUpload();
                        buildSubmit()
                    }
                });
            }
        });
    });

    function buildSubmit() {
        $('#btn_submit').on("click", function () {
            $.ajax({
                type:"post",
                url: 'user',
                data: $("#form_user").serialize(),
                success: function (result) {
                    layer.close(layer.index);
                }
            });

            return false;
        })
    }
    //绑定ajax上传文件
    function buildUpload() {
        $('#userFile').uploadifive({
            'auto': true,//是否自动上传
            'fileObjName': 'userFile',//上传的二进制数据的名称
            'fileType': 'image/*',//上传文件的类型 image/png,image/jpg,image/gif
            'buttonText': '提交用户头像',
            'uploadScript': 'user/upload',//上传的URL
            'onUploadComplete': function (file, data) {//上传成功后的回调
                console.log(data);
                $('#stuAvatar').val(data);
            },
        });
    }

})